package com.project.market.controller;

import com.project.market.service.AdminDashBoardService;
import com.project.market.service.impl.AdminDashBoardServiceImpl;
import com.project.market.util.JacksonUtil;
import com.project.market.util.ResponseUtil;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

@WebServlet("/admin/dashboard")
public class AdminDashBoardController extends HttpServlet {

    AdminDashBoardService adminDashBoardService = new AdminDashBoardServiceImpl();
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

        String[] str = new String[]{"goodsTotal","userTotal",
                "productTotal","orderTotal"};
        Integer[] ints = adminDashBoardService.getTotal(str);


        Map<String,Object> result = new HashMap<>();
        result.put("goodsTotal",ints[0]);
        result.put("userTotal",ints[1]);
        result.put("productTotal",ints[2]);
        result.put("orderTotal",ints[3]);
        Object ok = ResponseUtil.ok(result);
        String s = JacksonUtil.writeValueAsString(ok);
        resp.getWriter().println(s);
    }
}
